package b3.config
{
	public class ViewConfig extends BasicConfig
	{
		public var index:int;
		public var bgrImage:Array;
		public var baseImage:Array;
		public var objAppearHeight:Array;
		public var objAppearClass:Array;
		
		public function ViewConfig(viewXML:XML = null)
		{
			super(viewXML);
			if (viewXML != null)
			{
				objAppearHeight = new Array();
				objAppearClass = new Array();
				for (var i:int = 0; i < viewXML.objAppear.length(); i++)
				{
					var heights:Array = viewXML.objAppear[i].height.split(",");
					for (var j:int = 0; j < heights.length; j++)
					{
						objAppearHeight.push(parseFloat(heights[j]));
						objAppearClass.push(String(viewXML.objAppear[i].className));
					}
				}
				sortObjAppear();
			}
		}
		
		public function copy():ViewConfig
		{
			var viewConfig:ViewConfig = new ViewConfig();
			 viewConfig.index = this.index;
			 viewConfig.bgrImage = this.bgrImage.concat();
			 viewConfig.baseImage = this.baseImage.concat();
			 viewConfig.objAppearHeight = this.objAppearHeight.concat();
			 viewConfig.objAppearClass = this.objAppearClass.concat();
			 return viewConfig;
		}
		
		private function sortObjAppear():void
		{
			for (var i:int = objAppearHeight.length - 1; i > 0; i--)
			{
				for (var j:int = 0; j < i; j++)
				{
					if (objAppearHeight[j] > objAppearHeight[j + 1])
					{
						var tempHeight:Number = objAppearHeight[j];
						objAppearHeight[j] = objAppearHeight[j + 1];
						objAppearHeight[j + 1] = tempHeight; 
						var tempClass:String = objAppearClass[j];
						objAppearClass[j] = objAppearClass[j + 1];
						objAppearClass[j + 1] = tempClass; 
					} 
				}
			}
		}

	}
}